<template>
	<view class="wrap">
		<u-form :model="house" :rules="rules" ref="uForm" :errorType="errorType">
			<u-form-item label-width="120" label-position="top" label="名称" prop="houseName">
				<u-input placeholder="请输入畜舍名称" v-model="house.houseName" type="text"></u-input>
			</u-form-item>
			<u-form-item label-position="top" label="备注" prop="remark">
				<u-input type="textarea" placeholder="请填写畜舍备注" v-model="house.remark" />
			</u-form-item>
		</u-form>
		<u-button type="primary" @click="submit">保存</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				house: {},
				rules: {
					houseName: [{
						required: true,
						message: '请输入畜舍名称',
						trigger: 'blur'
					}]
				},
				errorType: ['message']
			};
		},
		onLoad(e) {
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit: function() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						uni.showLoading()
						this.$u.api.addHouse(this.house).then(res => {
							this.$dm.showSuccess()
							setTimeout(() => {
								uni.navigateBack()
							}, 1500)
						})
					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 30rpx;
	}

	.u-form {
		margin-bottom: 20px;
	}
</style>
